{include file="common/head"/}
<style type="text/css"> 
body,html{ background: #fff }
.layui-form-select dl{ max-height: 158px!important }
.layui-table-view{ margin: 0px!important; }
</style> 
<div class="main">
    <div class="layui-card-header">下级码商列表</div> 
    <div class="pd15">
        <blockquote class="layui-elem-quote">
            <a class="layui-btn layui-btn-sm" href="{:url(index)}">刷新全部</a>
            <div class="layui-btn layui-btn-sm" id="addusers">新增码商</div>
            <div class="layui-btn layui-btn-primary layui-btn-sm"><span class="red">锁定码商：</span>{$agentinfo.lock}，<span class="gre">激活码商：</span>{$agentinfo.open}</div>
        </blockquote> 
        <table class="layui-table layui-hide" id="list" lay-filter="list"></table>
    </div> 
</div>
<script type="text/html" id="is_lock">
    <input type="checkbox" name="is_lock" value="{{d.id}}" lay-skin="switch" lay-text="正常|禁用" lay-filter="is_lock" {{ d.is_lock == 0 ? 'checked' : '' }}>
</script>
<script type="text/html" id="action">
    <div lay-event="channeladd" title="新增通道" class="layui-btn layui-btn-xs">新增通道</div> 
</script>   
<script type="text/html" id="channel"><div class="layui-btn layui-btn-primary layui-btn-xs" lay-event="channellist">码商通道</div></script>  
<script type="text/html" id="order"><div class="layui-btn layui-btn-primary layui-btn-xs" lay-event="orderlist">订单明细</div></script>   
<script src="/static/plugins/layui/layui.js"></script> 
<script>
    layui.use(['table','form'], function() {
        var table = layui.table,form = layui.form, $ = layui.jquery;
        var tableIn = table.render({
            id: 'user',
            elem: '#list',
            url: '{:url("index")}',
            method: 'post',  
            page: true,
            cols: [[ 
                // {field: 'id', title: '{:lang("id")}', width: 80, fixed: true},
                {field: 'id', title: 'ID',align: 'center', width: 130, fixed: true}, 
                {field: 'username', title: '姓名',align: 'center', width: 130, fixed: true}, 
                {field: 'mobile', title: '联系电话', width: 150}, 
                {field: 'email', title: '联系邮箱', width: 170}, 
                {field: 'level_name', title: '码商等级',align: 'center', width: 100}, 
                {field: 'channels', title: '码商通道',align: 'center', width: 100,templet: '#channel'}, 
                {title: '所有订单', align: 'center',width: 100,templet: '#order'},  
                {field: 'is_lock', align: 'center',title: '码商状态', width: 120,toolbar: '#is_lock'},
                {field: 'reg_time', title: '开通时间', width: 150},
                //{width: 120, align: 'center', title: '操作', toolbar: '#action', fixed:'right'}
            ]],
            limit: 10 //每页默认显示的数量
        });  
          
        form.on('switch(is_lock)', function(obj){ 
            var id = this.value; 
            var is_lock = obj.elem.checked===true?0:1;
            $.post('{:url("user/agent/usersState")}',{'userid':id,'is_lock':is_lock},function (res) { 
                if (res.status===1) { 
                    layer.msg(res.msg,{time:1000,icon:1},function(){
                        tableIn.reload();
                    }); 
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                    return false;
                }
            })
        });
        $('#addusers').on('click', function() {
            var key = $('#key').val();
            layer.open({
                type: 2,
                title:'新增码商',
                shade: 0.5,
                shadeClose: true,
                area: ['380px', '574px'], 
                content:"{:url('user/regmin/reg')}?agentid={$userInfo.id}",
            }); 
        }); 
        table.on('tool(list)', function(obj) {
            var data = obj.data; 
            console.log(data.id);
            if(obj.event === 'orderlist') {
                layer.open({
                    type: 2,
                    title:'订单列表',
                    shade: 0.5,
                    shadeClose: true,
                    area: ['80%', '90%'], 
                    content:"{:url('order/ordermin')}?userid="+data.id,
                });    
            }
            if(obj.event === 'channellist') {
                layer.open({
                    type: 2,
                    title:'通道列表',
                    shade: 0.5,
                    shadeClose: true,
                    area: ['80%', '90%'], 
                    content:"{:url('channel/channelmin')}?userid="+data.id+"&username="+data.username+"&mobile="+data.mobile,
                });    
            } 
            if(obj.event === 'channeladd') {
                layer.open({
                    type: 2,
                    title:'新增通道',
                    shade: 0.5,
                    shadeClose: true,
                    area: ['380px', '344px'], 
                    content:"{:url('channel/addchannel')}?userid="+data.id+"&userlv="+data.userlv,
                });    
            }  
        }); 
    }); 
</script>
</body>
</html>